package com.edu.exam.entity.examination.paper.technical;

import com.edu.exam.enums.examination.paper.OmRecognitionAlgorithmType;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * OMR识别配置实体类
 *
 * 根据E-04-03 OMR识别子模块数据库设计实现
 * 存储OMR识别算法配置和参数，支持多种识别算法的配置管理。
 *
 * @author System
 * @version 1.0.0
 */

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class OmRecognitionConfig {

    /**
     * 配置ID，主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "config_id")
    private Long configId;

    /**
     * 配置基本信息
     */
    @Column(name = "config_name", length = 200, nullable = false)
    private String configName;

    @Column(name = "config_description", columnDefinition = "TEXT")
    private String configDescription;

    @Column(name = "config_version", length = 50, nullable = false)
    private String configVersion;

    @Enumerated(EnumType.STRING)
    @Column(name = "algorithm_type", length = 20, nullable = false)
    private OmRecognitionAlgorithmType algorithmType;

    /**
     * 算法配置（JSON格式）
     */
    @Column(name = "preprocessing_config", columnDefinition = "JSON")
    private String preprocessingConfig;

    @Column(name = "recognition_config", columnDefinition = "JSON")
    private String recognitionConfig;

    @Column(name = "postprocessing_config", columnDefinition = "JSON")
    private String postprocessingConfig;

    @Column(name = "quality_config", columnDefinition = "JSON")
    private String qualityConfig;

    /**
     * 适用条件（JSON格式）
     */
    @Column(name = "supported_sheet_types", columnDefinition = "JSON")
    private String supportedSheetTypes;

    @Column(name = "quality_requirements", columnDefinition = "JSON")
    private String qualityRequirements;

    @Column(name = "processing_scenarios", columnDefinition = "JSON")
    private String processingScenarios;

    @Column(name = "question_types", columnDefinition = "JSON")
    private String questionTypes;

    /**
     * 性能指标
     */
    @Column(name = "expected_accuracy", precision = 5, scale = 2)
    private Double expectedAccuracy;

    @Column(name = "processing_speed", precision = 8, scale = 2)
    private Double processingSpeed;

    @Column(name = "resource_requirements", columnDefinition = "JSON")
    private String resourceRequirements;

    /**
     * 配置管理
     */
    @Column(name = "is_default", nullable = false)
    private Boolean isDefault;

    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    @Column(name = "template_id")
    private Long templateId;

    /**
     * 激活时间
     */
    @Column(name = "activated_time")
    private LocalDateTime activatedTime;

    /**
     * 创建和修改人信息
     */
    @Column(name = "created_by", nullable = false)
    private Long createdBy;

    @Column(name = "updated_by")
    private Long updatedBy;

    /**
     * 版本控制
     */
    @Column(name = "parent_config_id")
    private Long parentConfigId;

    @Column(name = "version_notes", columnDefinition = "TEXT")
    private String versionNotes;

    // ===== 审计字段 =====

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 版本号（乐观锁）
     */
    @Version
    @Column(name = "version")
    private Integer version = 0;

    /**
     * 逻辑删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;
}